<template>
	<view class="fileBack">
		<view class="main">
			<view>
				<view class="title mab5">请选择打印项目</view>
				<view class="display" style="flex-flow: wrap">
					<view class="displayAli_cen wid50 mab20" v-for="(item, index) in printFileList" :key="index" @click="checkFile(item,index)">
						<checkBox :checked="item.checked"></checkBox>
						<text style="margin-left: 10rpx">{{ item.name }}</text>
					</view>
				</view>
			</view>
			<view>
				<view class="displayAli_cen justify-spb">
					<view class="title">请选择打印机</view>
					<view class="" @click="radioPrinter('')">
						<u-button style="width: 70px;" type="primary" shape="circle" plain color='#166ffc' size="small" text="取消选中"></u-button>
					</view>
				</view>
				<view class="displayAli_cen" style="flex-flow: wrap">
					<view class="wid50 mab20" :class="item==checkPrinter?'mode-radio1':'mode-radio'" v-for="(item, index) in printerList" :key="index" @click="radioPrinter(item,index)">
							<text class="padL10">{{item}}</text>
					</view>
				</view>
			</view>
		</view>
	
		<view class="">
			
		</view>
	</view>
</template>

<script>
	export default {
		name:"printPop",
		props:{
			checkFileList:{ //已选择的打印文件列表
				type:String,
				default:'',
			},
			checkPrinter:{ //已选择的打印机
				type:String,
				default:'',
			},
			isPrintPop:{ // 用于监听刷新组件
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				printFileList:[], //可打印文件列表
				printerList:[],  //可选打印机列表
			};
		},
		watch:{
			isPrintPop(n,o){
				console.log('监听组件打开',n)
			}
		},
		mounted() {
			this.encodeConfig();//查询收费配置
			this.getPrinter() //查询打印配置  站点打印机
		},
		methods:{
			checkFile(item,index){ // 多选打印文件
				item.checked=!item.checked
				this.$emit('checkFile',this.printFileList)
			},
			radioPrinter(item,index){ // 单选打印机
				this.$emit('radioPrinter',item)
			},
			
			// ---------------- 接口请求
			async getPrinter(){ // 获取站点打印机
				let param = {
					stationId: uni.getStorageSync('stationId'),
					itemName1: "打印配置",
					itemName2: "打印机配置",
				}
				this.$ajax.myRequest({
					url: this.$config.pathStation + 'config/encode/byEntity',
					data: param,
					header: {
						'content-type': 'application/json;charset=UTF-8'
					},
					method: 'POST',
					success: (res) => {
						if (res.data.code == 1) {
							let data = res.data.data
							this.printerList=[]
							data.forEach(i=>{
								this.printerList.push(i.itemValue2)
							})
							if(!this.checkPrinter && this.printerList[0]){ // 如果未选择打印机 且配置了打印机
								this.radioPrinter(this.printerList[0])
							}
						}
					},
				})
			},
			async encodeConfig() { // 获取收费配置
				let param = {
					stationId: uni.getStorageSync('stationId'),
					itemName1: "收费",
				}
				this.$ajax.myRequest({
					url: this.$config.pathStation + 'config/encode',
					data: param,
					method: 'GET',
					success: (res) => {
						if (res.data.code == 1) {
							let data = res.data.data
							let chargeInfoData = []
							let printList=[]
							for (var key in data) {
								if (key.indexOf("sf_syt_zddyxx_sj") != -1 && data[key].itemValue1 == 'Y') { //收据
									printList.push(print('收据'))
								}
								if (key.indexOf("sf_syt_zddyxx_pzsqb") != -1 && data[key].itemValue1 == 'Y') { //申请单
									printList.push(print('牌证申请单'))
								}
								if (key.indexOf("sf_syt_zddyxx_hjwjd") != -1 && data[key].itemValue1 == 'Y') { //环检外检单
									printList.push(print('环检外检单'))
								}
								if (key.indexOf("sf_syt_zddyxx_ajwjd") != -1 && data[key].itemValue1 == 'Y') { //安检外检单
									printList.push(print('安检外检单'))
								}
								this.printFileList=printList
								function print(name){
									return {
										checked:true,
										name:name
									}
								}
							}
							
							// 处理打印项目
							let checkFileList=this.checkFileList.split(',') 
							let checkFileList1=[]
							this.printFileList.forEach(i=>{
								if(this.checkFileList&&!checkFileList.includes(i.name)){ // 有缓存且缓存不存在该打印项目
									i.checked=false
								}
								if(i.checked){
									checkFileList1.push(i.name)
								}
							})
							if(!this.checkFileList){ // 如果未选择打印项目 且配置了打印项目
								this.$emit('checkFile',this.printFileList)
							}
							// checkFileList1.forEach((item,index)=>{
							// 	this.checkFile(item,index)
							// })
							
						}
				
					}
				});
				
			},
			
		},
	}
</script>

<style lang="scss">
// 打印选择
.fileBack {
	width: 100%;
	max-height: 50vh;
	
	.title {
		padding: 30rpx 0;
		font-size: 16px;
		font-weight: 700;
		color:#000;
	}
	
	.main {
		padding: 0 30rpx;
		min-height: calc(50vh - 110rpx);
		overflow: scroll;
		/* #ifdef MP-WEIXIN */
		radio::before {
			left: 5px;
		}
		/* #endif */
	}
	
}
</style>